package com.example.springvue.service.Impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.springvue.mapper.AuthGroupAccessMapper;
import com.example.springvue.model.AuthGroupAccess;
import com.example.springvue.service.AuthGroupAccessService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AuthGroupAccessServiceImpl implements AuthGroupAccessService {
    @Resource
    private AuthGroupAccessMapper authGroupAccessMapper;



    //添加
    @Override
    public boolean Add(int uid,int group_id) {
        AuthGroupAccess authGroupAccess = new AuthGroupAccess();
        authGroupAccess.setUid(uid);
        authGroupAccess.setGroupId(group_id);
        int add = authGroupAccessMapper.insert(authGroupAccess);
        if (add==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean Edit(int uid,int group_id) {

        UpdateWrapper<AuthGroupAccess> authGroupAccessUpdateWrapper = new UpdateWrapper<>();

        AuthGroupAccess authGroupAccess = new AuthGroupAccess();
        authGroupAccess.setUid(uid);
        authGroupAccess.setGroupId(group_id);
        LambdaUpdateWrapper<AuthGroupAccess> eq = authGroupAccessUpdateWrapper.lambda().eq(AuthGroupAccess::getUid,uid);
        int edit = authGroupAccessMapper.update(authGroupAccess,eq);
        if (edit==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(String[] id) {
        UpdateWrapper<AuthGroupAccess> authGroupAccessUpdateWrapper = new UpdateWrapper<>();

        LambdaUpdateWrapper<AuthGroupAccess> eq = authGroupAccessUpdateWrapper.lambda().in(AuthGroupAccess::getUid,id);
        int delete = authGroupAccessMapper.delete(eq);
        return true;
    }
}
